checkbutton: Add a warning about cyclic groups
authorMatthias Clasen <mclasen@redhat.com>
Wed, 17 Mar 2021 11:37:33 +0000 (07:37 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 17 Mar 2021 11:38:57 +0000 (07:38 -0400)
Setting up check or toggle button group relationships
in a cycle will lead to lockups. Add a warning about
this, and catch the simplest case with a precondition
check.

Fixes: #3763
gtk/gtkcheckbutton.c
gtk/gtktogglebutton.c

index 366fd2398c9c816ac776717f5eb2e4aaccf61c02..e9a30a1ce3e67de953133431cefffca29d5e9dbf 100644 (file)
@@ -913,6 +913,8 @@ gtk_check_button_set_label (GtkCheckButton *self,
  * Setting the group of a check button also changes the css name of the
  * indicator widget's CSS node to 'radio'.
  *
+ * Setting up groups in a cycle leads to undefined behavior.
+ *
  * Note that the same effect can be achieved via the [interface@Gtk.Actionable]
  * API, by using the same action with parameter type and state type 's'
  * for all buttons in the group, and giving each button its own target
@@ -926,6 +928,7 @@ gtk_check_button_set_group (GtkCheckButton *self,
   GtkCheckButtonPrivate *group_priv = gtk_check_button_get_instance_private (group);
 
   g_return_if_fail (GTK_IS_CHECK_BUTTON (self));
+  g_return_if_fail (self != group);
 
   if (!group)
     {
index 6ae96fc8afeb413d43eb4f82ccee37324fdd5288..1e53a896c671fccf95047248c97f6b195bdad4ab 100644 (file)
@@ -473,6 +473,8 @@ gtk_toggle_button_toggled (GtkToggleButton *toggle_button)
  * In a group of multiple toggle buttons, only one button can be active
  * at a time.
  *
+ * Setting up groups in a cycle leads to undefined behavior.
+ *
  * Note that the same effect can be achieved via the [interface@Gtk.Actionable]
  * API, by using the same action with parameter type and state type 's'
  * for all buttons in the group, and giving each button its own target
@@ -486,6 +488,7 @@ gtk_toggle_button_set_group (GtkToggleButton *toggle_button,
   GtkToggleButtonPrivate *group_priv = gtk_toggle_button_get_instance_private (group);
 
   g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
+  g_return_if_fail (toggle_button != group);
 
   if (!group)
     {